/**
 * @file driver.h
 * @brief driver struct
 * @author    - Adela 
 *            - Robert Zhang <armner@gmail.com>
 *            - 
 */
#ifndef _DRIVER_H_
#define _DRIVER_H_

#ifdef __cplusplus
extern "C" {
#endif


typedef int  OFFSET;

typedef struct struct_driver
{
/**
 * @brief open method of a driver
 * @param driver - pointer to a Driver struct
 * @return 0 success; other failed
 */
    int (*open)(struct struct_driver* driver);
/**
 * @brief write method of a driver
 * @param driver -pointer to a Driver
 * @param buffer - pointer to data source
 * @param len - length of data to be copied, in bytes
 * @param offset - write destination offset of a driver
 * @return number of bytes being copied.
 */
    int (*write)(struct struct_driver* driver, void *buffer, int len, OFFSET offset);
/**
 * @brief read method of a driver
 * @param driver -pointer to a Driver
 * @param buffer - pointer to data destination
 * @param len - length of data to be copied, in bytes
 * @param offset - read destination offset of a driver
 * @return number of bytes being copied.
 */
    int (*read)(struct struct_driver* driver, void *buffer, int len, OFFSET offset);
/**
 * @brief control method of a driver
 * @param driver -pointer to a Driver
 * @param cmd - control command type. cmd can be "set" or "get", when set, data can be a pointer or values; when get, "data" always be pointers 
 * @param data - parameter passed to a command
 * @return 0 success;other fail.
 */
    int (*ioControl)(struct struct_driver *driver, int cmd, int data);
/**
 * @brief close method of a driver
 * @param driver- driver pointer to be closed
 * @return 0 success
 */
    int (*close)(struct struct_driver *driver);
} Driver, *pDriver;

#ifndef NULL
#define NULL    ((void *)0)
#endif

#ifdef __cplusplus
}
#endif


#endif
